<?php
/************************************* Core 开始***********************************************/
//获取频道目录名称
function getTreeName($tid) {
	static $_tree;
	$dao = D('Page', 'portal');
	$tid = explode(',', $tid);

	foreach ($tid as $v){
		if(empty($v)) continue;
		
		if(!array_key_exists($v, $_tree)){
			$get = $dao->where ('id='.$v )->field('name')->find();
			$_tree[$v] = $get['name'];			
		}
		
		$res[] = $_tree[$v];
	}
	
	return implode('->', $res);
}

function getManagerName($manager, $id){
	$managerArr = explode(',', $manager);
	foreach ($managerArr as $v){
		if(empty($v)) continue;		
		$res[] = "<a href=\"javascript:void(0)\" onclick=\"delAdmin($id,$v)\" title='点击删除该专题管理员'>".getUserName($v)."</a>";
	}
	
	return implode(',', $res);
}

function getStatusName($status){
	$config = array(0=>'未开通',1=>'开通');
	
	return $config[ $status ];
}

function getCategoryName($id){
	static $_category;
	
	if(empty($_category[$id])){
		$_category[$id] = D('Page', 'portal')->where("id='$id'")->getField('name');
	}
	
	return $_category[$id];	
}

function getChannelTitle($id){
	static $_channel;
	
	if(empty($_channel[$id])){
		$_channel[$id] = D('Channel', 'portal')->where("id='$id'")->getField('title');
	}
	
	return $_channel[$id];
}


//Tag统计  韦心红增加 2009-05-04
function get_X_Tag(){
	static $_tag;

	if(empty($_tag)){
		$count = 0;
		$list = M('x_tag')->field('tagid, tagname')->findAll();
		foreach ($list as $v){
			$count += 1;
			
			$_tag['name'][$v['tagid']] = $v['tagname'];
			$id[] = $v['tagid'];
		}

		$_tag['id'] = implode(',', $id);
		$_tag['count'] = $count;
	}

	return $_tag;
}
function getTagName($tagid){
	$tag = get_X_Tag();
	$tag = $tag['name'];
	
	return $tag[$tagid];
}

//过虑如123，456这样的数字串
function intMember($val){
	$isArr = is_array($val);
	
	if(!$isArr){
		$val = explode(',', $val);
	}
	
	foreach ($val as $k=>&$v){
		$v = intval($v);
		if(empty($v))	unset($val[$k]);
	}
	
	if($isArr){
		return $val;
	}

	return implode(',', $val);
}